<template>
	<view>
		<block v-if="list.length == 0">
			<view :style="{ height: (systemInfo.windowHeight - 120) + 'px'}">
				<u-empty icon="https://gxmanager.oss-cn-shenzhen.aliyuncs.com/xfqczbgl_static/no-data.png" iconSize="150" marginTop="50" text="暂无设备数据！"></u-empty>
			</view>
		</block>
		<block v-else>
			<scroll-view scroll-y>
				<view class="base-list">
					<view class="base-item" v-for="(item,index) in list" :key="index">
						<view class="base-info row">
							<view class="base-content u-flex-row u-row-between" style="margin-left: 0;padding-bottom: 0">
								<view class="u-flex-row align-center">
									<view class="notic-title" style="font-size: 34rpx;font-weight: bold;">{{ item.deviceDeptName }}-<text :class="item.deviceStatus == 0 ? 'text-red' : 'text-green'">{{ item.deviceStatus == 0 ? '离线' : '在线'  }}</text></view>
								</view>
								<view class="u-m-l-20" style="min-width: 200rpx;" @click="openDoor(item)">
									<button type="primary" :disabled="item.deviceStatus == 0 ? true : false">开闸</button>
								</view>
							</view>
						</view>
					</view>
				</view>
			</scroll-view>
			<u-loadmore :status="status" />
		</block>
		<u-gap height="200" v-if="list.length != 0"></u-gap>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: 'loadmore',
				list: [],
				page: 1,
				limit: 10,
				total: 0
			};
		},
		onReachBottom() {
			// 判断数据是否全部加载完毕，true则停止请求接口，修改loadingmore状态
			if (this.list.length >= this.total) {
				this.status = 'nomore'
				return;
			}
			this.status = 'loading';
			this.page += 1;
			this.getListData(true); //调用数据
		},
		methods: {
			getListData(isPush = false) {
				this.$api.deviceList({
					orderColumn: 'createTime',
					orderDirection: 'descending',
					pageNum: this.page,
					pageSize: this.limit,
				}).then(res => {
					let data = res.data.rows
					this.total = res.data.total
					if (!isPush) {
						this.list = []
					}
					if (this.total < this.limit) { // 不足10条数据
						this.status = 'nomore'
					}
					for (let i of data) {
						this.list.push(i)
					}
				})
			},
			navTo(path, params) {
				this.$Router.push({ name: path, params })
			},
			reset() {
				this.status = 'loading';
				this.page = 1
				this.list = []
				this.getListData()
			},
			openDoor(item) {
				if (item.deviceStatus == 0) {
					return
				}
				this.$api.openDoor({
					machineId: item.id
				}).then(res => {
					uni.showToast({
						title: '开闸成功！'
					});
				}).catch(() => {
					uni.showToast({
						title: '操作失败！',
						icon: 'none'
					});
				})
			}
		},
		onLoad() {
			this.getListData()
		}
	}
</script>

<style>
	page {
		background-color: #F7F7F7;
	}
	.notic-title{
		font-size: 28rpx;
	}
	.notic-desc{
		margin-top: 24rpx;
		font-size: 24rpx;
		justify-content: space-between;
		align-items: center;
	}
	.list-search {
		padding: 24rpx 28rpx;
		background-color: #fff;
	}
	.downMenu{
		padding: 8rpx 15rpx;
		background: #F7F7F7;
		border-radius: 4rpx;
		margin: 0 30rpx 30rpx 0;
		border: 1rpx solid #F7F7F7;
	}
	
	.silk-ribbon {
		display: flex;
		justify-content: center;
		position: absolute;
		right: 0;
		color: #FFFFFF;
	}
	
	.silk-ribbon:nth-child(even) {
		margin-right: 4%;
	}
	
	.silk-ribbon1 {
		position: absolute;
		top: -18px;
		right: 25px;
	}
	
	.silk-ribbon1:after {
		position: absolute;
		content: "";
		display: block;
		width: 0;
		height: 0;
		border-left: 53px solid transparent;
		border-right: 53px solid transparent;
		border-top: 10px solid #379b9c;
	}
	
	.silk-ribbon1 span {
		position: relative;
		display: inline-block;
		text-align: center;
		background: #379b9c;
		font-size: 14px;
		line-height: 1;
		padding: 12px 8px 10px;
		border-top-right-radius: 8px;
		width: 90px;
	}
	
	.silk-ribbon1 span:before,
	.silk-ribbon1 span:after {
		position: absolute;
		content: "";
		display: block;
	}
	
	.silk-ribbon1 span:before {
		background: #379b9c;
		height: 6px;
		width: 6px;
		left: -6px;
		top: 0;
	}
	
	.silk-ribbon1 span:after {
		background: #337e7f;
		height: 6px;
		width: 8px;
		border-radius: 8px 8px 0 0;
		left: -8px;
		top: 0;
	}

	.silk-ribbon1.green:after{
		border-top-color: #00B96B;
	}
	.silk-ribbon1.green span,
	.silk-ribbon1.green span:before,
	.silk-ribbon1.green span:after{
		background: #00B96B;
	}
	
	.silk-ribbon1.yellow:after{
		border-top-color: #F2BD27;
	}
	.silk-ribbon1.yellow span,
	.silk-ribbon1.yellow span:before,
	.silk-ribbon1.yellow span:after{
		background: #F2BD27;
	}
</style>
